// 工程质量

// 过程检查-选择位置
// 位置赋值的全部相关字段
const assignAreaAllFields = [
  // 'projectId',
  // 'fileId',
  // 'taskFileId',
  // 'itemFileId',
  // 'taskId',
  // 'standardId',
  // 'mrqId',
  // 'scoreItemId',
  'rectifyId',
  'standardType',
  'publlicFileId',
  'shortName',
  'buildingId',
  'floor',
  'roomId',
  'pileName',
  'drawArea',
  'direction'
]
// 可选字段
const assignAreaOptionalFields = ['rectifyId', 'standardType', 'publlicFileId', 'shortName']
// 必须字段
const assignAreaRequiredFields = {
  1: ['buildingId', 'floor'],
  2: ['buildingId', 'roomId'],
  3: ['buildingId'],
  4: ['buildingId', 'pileName'],
  5: ['buildingId', 'drawArea'],
  6: ['buildingId', 'direction'],
  7: ['buildingId'],
  8: ['buildingId', 'drawArea']
}
// 根据 unitType，从 source 取对应几个字段的有效值，赋值到 target，并删除 target 其他位置字段值
export const assignAreaPosition = (unitType, target, source) => {
  assignAreaAllFields.map(k => delete target[k])
  const obj = {}
  const requiredFields = assignAreaRequiredFields[unitType] || []
  requiredFields.map(k => (obj[k] = source[k]))
  assignAreaOptionalFields.map(k => typeof source[k] !== 'undefined' && (obj[k] = source[k]))
  Object.assign(target, obj)
  return obj
}

// taskRectify 生成 tmpId 的字段
const taskRectifyTmpIdFields = {
  1: ['buildingId', 'floor'],
  2: ['buildingId', 'roomId'],
  3: ['buildingId'],
  4: ['buildingId'],
  5: ['buildingId'],
  6: ['buildingId', 'direction'],
  7: ['buildingId'],
  8: ['buildingId']
}
export function generateTaskRectifyTmpId(unitType, position) {
  if (!unitType) return
  const fields = taskRectifyTmpIdFields[unitType]
  if (!fields) return
  const str = fields
    .map(field => position[field])
    .filter(i => i)
    .join('_')
  if (!str) return
  return `${unitType}_${str}`
}
